package com.hospital.yygh.cmn.config;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * mapper配置类，其实在mapper接口那里直接加@Mapper也可以的
 */
@Configuration
@MapperScan("com.hospital.yygh.cmn.mapper")
public class CmnConfig {

    /**
     * 分页插件
     */
//    @Bean
//    public PaginationInterceptor paginationInterceptor() {
//        return new PaginationInterceptor();
//    }

    /**
     * 分页插件，这个方法(PaginationInterceptor)在高版本springboot中已经过时了
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        // mp插件接口
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        // 添加乐观锁插件
        interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
        return interceptor;
    }
}
